#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#define FILENAME "myfifo"



int main()
{
  int fd = open(FILENAME , O_RDWR);
  if (fd < 0)
  {
    perror("open error\n");
    exit(-1);
  }

  char msg[128];
  while(1)
  {
    msg[0] = 0; 
    printf("Please write :");
    fflush(stdout);
    // the screen is line fflush but there is no \n
    ssize_t s = read (0 , msg , sizeof(msg) - 1);
    if (s > 0)
    {
      msg[s-1] = 0; // because the end of msg is :xxxx\n\0
      write(fd , msg , strlen(msg));
    }
  }
  close(fd);
  return 0;
}
